const baseUrl = 'http://81.71.65.4:3003'; 

const request = (url,data={}, method='GET')=> {
	uni.showLoading({ 
		title:'努力加载中...'
	})
	return new Promise((resolve,reject)=> {
		uni.request({
			url: baseUrl+url,
			method,
			data,
			success: (res) => {
				if (res.data.code == 666) {
					resolve(res.data);	
				} else {
					uni.showToast({
						icon: 'error',
						title: '网络请求失败'
					})
					reject(res.data.msg);
				}
				
			},
			fail: (err) => { 
				uni.showToast({
					icon: 'error',
					title: '网络请求失败'
				})
				reject('网络请求失败');
			},
			complete: () => {
				uni.hideLoading();
			}
		})
	})
}


export const get = (url,data={})=> {
	 return request(url,data,'GET');
}
export const post = (url,data={})=> {
	 return request(url,data,'POST');
}